package com.ebs.md.fxmonitor;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/FxmonitorApp.java $
 *  $Revision: #5 $  $Change: 115590 $  $DateTime: 2012/10/11 12:27:52 $  $Author: Arik.Sher $
 */

import java.io.InputStream;

import org.apache.log4j.Logger;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ebs.commons.logger.MessageText;
import com.ebs.commons.threads.EbsThreadFactory;


public class FxmonitorApp implements Runnable {
    private Logger m_logger;

    public static void main(String[] args) {
        EbsThreadFactory threadFactory = new EbsThreadFactory("FxMonitor");
        Thread thread = threadFactory.newNonDaemonThread(new FxmonitorApp());
        thread.start();
    }

    public void run() {
        try {
            m_logger = Logger.getLogger(FxmonitorApp.class);
            m_logger.info("======== Starting FxMonitor =============");            
            InputStream is = this.getClass().getResourceAsStream("/messages.xml");
            
//            MessageText.setMessageMap(getClass().getResourceAsStream("/messages.xml"));
//            if(is == null)
//            {
//            	throw new RuntimeException("Property messages.xml is not defined.");
//            }
//            else
//            {
//            	System.out.println(is);
//            }
//            MessageText.setMessageMap(is);
            
            String configuration = System.getProperty("fxmonitor.configuration");
            if (null == configuration) {
                throw new RuntimeException("Property \"fxmonitor.configuration\" is not defined.");
            }

            ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext(configuration.split(","));
            factory.registerShutdownHook();

            //CentralMediator centralMediator = (CentralMediator) factory.getBean("centralMediator");
            //centralMediator.kickstart();

            AppInfo appInfo = (AppInfo) factory.getBean("fxmonitorInfo");
            m_logger.info("Name: " + appInfo.getName());
            m_logger.info("Version: " + appInfo.getVersion());
            m_logger.info("Description: " + appInfo.getDescription());
            m_logger.info("Start Date " + appInfo.getStartDate());
            m_logger.info("Up and running...");  // Make them think we're doing something...
        }
        catch (Exception e) {
            System.out.println("run exception");
            e.printStackTrace();
            System.exit(-1);
        }
    }
}
